package euler.p051_100;

import java.util.Arrays;

import euler.MainEuler;
import euler.helper.NaturalHelper;

public class Euler052 extends MainEuler {

    /*
        It can be seen that the number, 125874,
        and its double, 251748, contain exactly
        the same digits, but in a different order.

        Find the smallest positive integer, x,
        such that 2x, 3x, 4x, 5x, and 6x,
        contain the same digits.
     */
    public String resolve() {

        for (int power10 = 10; ; power10*=10) {
            for (int i = power10; 6*i < 10*power10; i++) {

                int[] di1 = NaturalHelper.digitos(i,10,true);
                int[] di2 = NaturalHelper.digitos(2*i,10,true);

                if (Arrays.equals(di1, di2)) {
                    int[] di3 = NaturalHelper.digitos(3*i,10,true);
                    if (Arrays.equals(di1, di3)) {
                        int[] di4 = NaturalHelper.digitos(4*i,10,true);
                        if (Arrays.equals(di1, di4)) {
                            int[] di5 = NaturalHelper.digitos(5*i,10,true);
                            if (Arrays.equals(di1, di5)) {
                                int[] di6 = NaturalHelper.digitos(6*i,10,true);
                                if (Arrays.equals(di1, di6)) {
                                    // 142857
                                    return String.valueOf(i);
                                }
                            }
                        }
                    }
                }
            }
        }
    }

}
